home *** CD-ROM | disk | FTP | other *** search
- /*
- * ---------------------------------------------------------------------
- * AEUtilities.c :
- *
- * © Copyright 1992 by F. Menneteau. All rights reserved.
- * This code can be both distributed and used freely.
- *
- * ---------------------------------------------------------------------
- */
-
-
- #include "CGenericAE.h"
-
-
- /* ---------------- */
- /* GetTargetID (G) */
- /* ---------------- */
- OSErr GetTargetID(
- Str31 TheZone,
- Str31 TheServer, // The (remote or local) machine
- Str32 TheTargetName,
- TargetIDPtr TheTargetIDPtr
- )
- {
- OSErr LcOSErr ;
- IPCListPortsPBRec LcIPCListPortsPBRec ;
- PortInfoRec LcBufferPortInfoRec ; // Usually an array
- LocationNameRec LcLocNameRec ;
- PPCPortRec LcPPCPortRec ;
-
- /*
- * Notes:
- * TheZone can be obtain either by calling GetZoneList() (which
- * gives a list of all the zone names on the internet), or
- * GetLocalZones() (list of zone names on the local network), or
- * GetMyZone() (the AppleTalk zone name of your local node).
- *
- * TheServer can be obtain by calling PLookupName() (which gives
- * a list of computers with ports).
- */
-
- /*
- * Build the PPCPortRec structure
- */
- LcPPCPortRec.nameScript = smRoman ;
- pstrcpy((Ptr) LcPPCPortRec.name,(Ptr) TheTargetName) ;
-
- LcPPCPortRec.portKindSelector = ppcByString ;
- pstrcpy((Ptr) LcPPCPortRec.u.portTypeStr,(Ptr) "\p=") ; // Match all types
-
- /*
- * Build the LocationNameRec structure (ppcNoLocation is used
- * when the location is on the local machine).
- */
- LcLocNameRec.locationKindSelector = ppcNBPLocation ;
- pstrcpy((Ptr) LcLocNameRec.u.nbpEntity.objStr,(Ptr) TheServer) ;
- pstrcpy((Ptr) LcLocNameRec.u.nbpEntity.typeStr,PPCTOOLBOX) ;
- pstrcpy((Ptr) LcLocNameRec.u.nbpEntity.zoneStr,(Ptr) TheZone) ;
-
- /*
- * Build the LcIPCListPortsPBRec structure.
- */
- LcIPCListPortsPBRec.startIndex = 0 ;
- LcIPCListPortsPBRec.requestCount = 1 ;
- LcIPCListPortsPBRec.portName = &LcPPCPortRec ;
- LcIPCListPortsPBRec.locationName = &LcLocNameRec ;
- LcIPCListPortsPBRec.bufferPtr = &LcBufferPortInfoRec ; // 1 item
-
- /*
- * This function returns information about ports that are on the
- * computer (TheServer) specified in the locationName field of
- * the list ports parameter block: IPCListPortsPBRec.locationName.
- *
- * Here however, we only search for the port of the TheTargetName.
- */
- LcOSErr = IPCListPorts(&LcIPCListPortsPBRec,FALSE) ;
-
- if ( (LcIPCListPortsPBRec.actualCount == 1 ) && (LcOSErr == noErr) ) {
- TheTargetIDPtr->name = LcBufferPortInfoRec.name ;
- TheTargetIDPtr->location= LcLocNameRec ;
- }
-
- return(LcOSErr) ;
- }
-
-
- /* ------------------------ */
- /* EntityPathToAlias (G) */
- /* ------------------------ */
- OSErr EntityPathToAlias(
- Ptr TheEntityPath,
- TypeEntity TheTypeEntity,
- AliasHandle *TheAliasHandle)
- {
- Str255 LcEntityPath ;
- OSErr LcOSErr ;
- FSSpec LcFSSpec ;
-
- if ( TheEntityPath == (Ptr) NULL )
- return(bdNamErr) ;
-
- /*
- * Save Entity name because we can modify it.
- */
- pstrcpy((Ptr) LcEntityPath,TheEntityPath) ;
-
- if ( (TheTypeEntity == typeFOLDER) &&
- PSTRLASTCHAR(LcEntityPath) != PSTRLASTCHAR(PDELIMITER)) {
- pstrcat((Ptr) LcEntityPath,PDELIMITER) ;
- }
-
- LcOSErr = FSMakeFSSpec(0,0,LcEntityPath,&LcFSSpec) ;
- RETN_IF_ERR(LcOSErr) ;
-
- LcOSErr = NewAlias((FSSpecPtr) NULL,&LcFSSpec,TheAliasHandle) ;
- RETN_IF_ERR(LcOSErr) ;
-
- if ( *TheAliasHandle == (AliasHandle) NULL )
- return(nilHandleErr) ;
-
- return(noErr) ;
- }
-
-
- /* -------------------- */
- /* GetProcessPSN (G) */
- /* -------------------- */
- OSErr GetProcessPSN(
- OSType TheProcessType,
- OSType TheProcessSignature,
- ProcessSerialNumberPtr ThePSNPtr)
- {
- ProcessInfoRec LcProcessInfo ;
- FSSpec LcFSSpec ;
-
- LcProcessInfo.processName = (StringPtr) NULL ;
- LcProcessInfo.processInfoLength = sizeof(LcProcessInfo) ;
- LcProcessInfo.processAppSpec = &LcFSSpec ;
-
- ThePSNPtr->highLongOfPSN = 0 ;
- ThePSNPtr->lowLongOfPSN = kNoProcess ;
-
- while( !GetNextProcess(ThePSNPtr) ) {
- if( !GetProcessInformation(ThePSNPtr,&LcProcessInfo) &&
- (LcProcessInfo.processType == TheProcessType) &&
- (LcProcessInfo.processSignature == TheProcessSignature) ) {
- return(noErr) ;
- }
- }
-
- return(procNotFound) ;
- }
-
-
- /* ---------------- */
- /* KillProcess (G) */
- /* ---------------- */
- OSErr KillProcess(
- Boolean TheAskApplFlag,
- Boolean TheWaitReplyFlag,
- OSType TheProcessType,
- OSType TheProcessSignature)
- {
- OSErr LcOSErr ;
- CGenericAE *LcCAE = new(CGenericAE) ;
-
- if ( TheAskApplFlag )
- LcOSErr = LcCAE->AskAndBuildTarget(sPSN) ;
- else
- LcOSErr = LcCAE->BuildTargetWithTypeAndSign(
- TheProcessType,TheProcessSignature) ;
- RETN_IF_ERR(LcOSErr) ;
-
- LcOSErr = LcCAE->CreateAE(kCoreEventClass,kAEQuitApplication) ;
- RETN_IF_ERR(LcOSErr) ;
-
- if ( TheWaitReplyFlag )
- LcOSErr = LcCAE->SendAEWithReply() ;
- else
- LcOSErr = LcCAE->SendAEWithoutReply() ;
-
- delete(LcCAE) ;
- return(LcOSErr) ;
- }
-
-